<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-合同库查看页</title>
		<style>
		#organizesTree {
			margin-top: 10px;
			border: 1px solid #617775;
			background: #f0f6e4;
			min-width: 180px;
			max-height: 400px;
			overflow-y: scroll;
			overflow-x: auto;
		}
		</style>
		<link rel="stylesheet" type="text/css"
			href="<%=request.getContextPath()%>/css/common.css" />
		<link rel="stylesheet" type="text/css"
			href="<%=request.getContextPath()%>/css/tag.css" />
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/jquery-1.7.2.js">
		</script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js">
		</script>
		
		<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/zTreeStyle/zTreeStyle.css" />	
		<link type="text/css" href="<%=request.getContextPath()%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.ztree.core-3.1.js"></script>
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.ztree.excheck-3.1.min.js"></script>
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js">
		</script>
		<script type="text/javascript">
			$(document).ready(function(){
		       var msg="${tagMessage}";
		        if(msg!=""){
			     alert(msg);
		      }
	         });
			function pageSub(currentPage) {
				var reg = /^\d*?$/;
				var total =${page.totalPages};
					 if(reg.test(currentPage)){
					 	if(currentPage > total){
					 		$("#currentPage").val(total);
					 	}else{
					 		$("#currentPage").val(currentPage);
					 	}
					 	
						document.forms[0].action="contractlist.action";
						document.forms[0].submit();
					}else{
						  alert("请输入数字!"); 
					}
				}
				
				function doSubmit(url){
					document.forms[0].action=url;
					document.forms[0].submit();
				}
				
		//删除合同动作
	     function delContract(contractID){
			if(confirm('确定删除该条记录？')){
			var url = encodeURI(encodeURI("deleteContract.action?contractID=" +contractID));
				$.ajax({
			        url: url,
			        type:"POST",
			        cache:false,
			        success: function(message)
			        {
				    	if(message == "success")
				    	{
			        		alert("合同删除成功！");
			        		doSubmit('contractlist.action');
			        	//	window.location.href="contractlist.action";
			        	}
			        	else if(message =="Nosuccess")
			        	{
				    		alert("媒体正在使用，合同删除失败！");
				    	//	doSubmit('contractlist.action');
				    	//	window.location.href="contractlist.action";
			        	}
				    	else if(message =="isDelete")
				    	{
				    		alert("该合同不存在，删除失败！");
				    		doSubmit('contractlist.action');
				    	//  window.location.href="contractlist.action";
				    	}
				    	else if(message =="error")
				    	{
				    		doSubmit('contractlist.action');
				    	//  window.location.href="goError.action";
				    	}
			   		}
		     	});
			}
	    }
	    
	    //重置
	    function resetFun()
	    {
            var myDate = new Date();
            var years = myDate.getYear();
	        document.getElementById("years").value=years;
			document.getElementById("contractLevel").value=""; 
			document.getElementById("inputValue").value="0";
			document.getElementById("inputKeyword").value="输入关键字搜索";
			document.getElementById("orgID").value="";
			document.getElementById("showOrganize").value="--部门科室--";
			document.getElementById("cityContract").value="${logUser.usercity}";
			getOrganization("${logUser.usercity}");
	     }
	     
	     //详情
	    function contractDetail(contractID){
		var url = encodeURI(encodeURI("turnToContractDetail.action?contractID=" +contractID+"&toType=1"));
		window.location.href=url;
	    }
	    //编辑
	    function contractMofify(contractID){
		var url = encodeURI(encodeURI("turnToContractModify.action?contractID=" +contractID));
		window.location.href=url;
	    }
	    function changeKeyword()
	     {				
		//提交
		  var inputkeyword =  document.getElementById("inputKeyword").value;
		  if(inputkeyword=='输入关键字搜索')
		  {
			   $('#inputKeyword').val('');
		  }
		 
	    }
	    function search()
	    {
	        var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;  
	        var inputKey = $.trim(document.getElementById("inputKeyword").value);
	        var inputValue = document.getElementById("inputValue").value;
            if(inputValue=='0'&&inputKey!='输入关键字搜索')
            {
            	alert("请选择关键字搜索条件！");
            	document.getElementById("inputKeyword").value="输入关键字搜索";
            }
            else
            {
	            document.getElementById("inputKeyword").value = inputKey;
		        if (inputKey != null && inputKey != '' && !myReg.test(inputKey)) {
				    alert("关键字不能包含：“$、#、%、/、*、<、>、'、\"、\\、& ”等特殊字符，请重新输入！");
				    document.getElementById('inputKeyword').focus();
				    return false;
		          }
		        doSubmit('contractlist.action'); 
            }
 
	       }
	    function trim(str) {
			str = str.replace(/^\s*/, "");
			str = str.replace(/\s*$/, "");
			str = str.replace(/^[" "|"　"]*/, "");
			str = str.replace(/[" "|"　"]*$/, "");
			return str;
		}
	   $(function(){
        //selectNav('nav1');
        });
	</script>
	</head>
	<body><input type="hidden" id="liValue"/>
	<jsp:include page="../common/top.jsp"></jsp:include>
		<!-- 顶部start -->
		<div id="main">
			<div class="body">
			<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
					<form action="" method="post" >
					    <input type="hidden" name="type" value="${type}"/>
						<table class="condition bg1"
							style="width: 100%; font-size: 14px; font-weight: bold; color: #000000;"
							align="center">
							<tr>
								<td width="8%" style="height: 40px; text-align:right;">
									<label>
										年份：
									</label>
	                       	     </td>  
	                       	     <td width="15%" style="height: 40px;">
	                       	        <s:select name="years" value="years" list="yearsList" listKey="contractYear" listValue="contractYear"
	                       	        ></s:select>
	                       	     </td >
	                       	     <td width="15%" style="height: 40px;">
	                       	        <s:select list="dataListQYJB" name="contractLevel" 
	                       	        listKey="id" listValue="datavalue" headerKey="" headerValue="--签约级别--"
	                       	        >
	                       	        </s:select>
								</td>
								<td width="15%" style="height: 40px;">
									<s:select name="contractCity" list="dataListCITY" id="cityContract" listKey="id" listValue="datavalue" onchange="getOrganization()" >
									</s:select>
								</td>
								<td width="15%" style="height: 40px;">
								    <input type="hidden"  id="orgID" name="contractOrganize" value="${contractOrganize}"/>
									<input name="text2" type="text" class="text" id="showOrganize"  style="color:#0078B6"
										 onkeydown="if(event.keyCode==8)return false;"
										onclick="showMenu('showOrganize', 'organizeContent');" value="${organizeValue}" readonly/>
								</td>
								<td width="30%" style="height: 40px;">
								&nbsp;&nbsp;&nbsp;
								</td>
							</tr>
							<tr>
								<td style="height: 40px; width: 8%; text-align:right;">
									<label>
										关键字：
									</label>
								</td>
								<td style="height: 40px; width: 15%;">
									<s:select name="keyword" list="#{1:'按供应商名称',2:'按签约人',3:'按合同名称'}" id="inputValue"
										listKey="key" listValue="value" headerKey="0" onchange="changeKeyword();"
										headerValue="--关键字检索类型--">
									</s:select>
								</td>
								<td style="height: 40px; width: 15%;">
									<input type="text"  name="inputKeyword" id="inputKeyword" class="text" value="${inputKeyword}" 
									 style= "text-valign:middle; line-height:23px; " onfocus="changeKeyword();"  onblur="if(this.value=='')this.value='输入关键字搜索'"
									/>
								</td>
								<td style="height: 40px;  text-align: left;" colspan="2">
									<input name="button" type="button" class="btn-title" value="搜索"
										onclick="search()" />
									&nbsp;&nbsp;&nbsp;
									<input name="button" type="button" class="btn-title" value="重置" 
									     onclick="resetFun()"/>
								</td>
								<td style="height: 40px; text-align: right;" valign="middle">
									<input type="button" value="合同导入" class="btn-title" onclick="doSubmit('toUploadContractAction.action');"/>
									&nbsp;&nbsp;
									<input type="button" class="btn-title" value="新增"
										onclick="doSubmit('toAddContract.action');" />
									&nbsp;&nbsp;&nbsp;
								</td>
							</tr>
						</table>

						<div id="list_div">
							<input type="hidden" name="currentPage" id="currentPage" />
							<table class="table_list" style="width: 100%; ">
								<tr class="bg">
									<th>
										合同编号
									</th>
									<th>
										合同名称
									</th>
									<th>
										合同类型
									</th>
									<th>
										供应商名称
									</th>
									<th>
										供应商类型
									</th>
									<th>
										签约级别
									</th>
									<th>
										所属地市
									</th>
									<th>
										部门科室
									</th>
									<th>
										签约人
									</th>
									<th>
										年份
									</th>
									<th>
										操作
									</th>
								</tr>
								<s:iterator value="list" id="clist">
									<tr>
										<td title="${clist.contractID}">
										${fn:substring(clist.contractID, 0, 12) }
										</td>
										<td title="${clist.contractName}">
										${fn:substring(clist.contractName, 0, 7) }
										</td>
										<td>
										  <s:iterator value="dataListHTLX" id="htlx">
                                             <s:if test="#htlx.id == #clist.contractType">
                                                 ${htlx.datavalue}
										     </s:if>
										  </s:iterator>
										</td>
										<td title="${clist.contractBName}">
											${fn:substring(clist.contractBName, 0, 7) }
										</td>
										<td>
										   <s:iterator value="dataListGYSLX" id="gyslx">
										     <s:if test="#gyslx.id == #clist.contractBType" >
										      ${gyslx.datavalue}
										     </s:if>
										   </s:iterator>
										</td>
										<td>
										  <s:iterator value="dataListQYJB" id="qyjb">
										    <s:if test="#qyjb.id ==#clist.contractLevel">
										     ${qyjb.datavalue}
										    </s:if>
										  </s:iterator>
										</td>
										<td>
										 <s:iterator value="dataListCITY" id="city">
                                             <s:if test="#city.id == #clist.contractCity">
                                                 ${city.datavalue}
										     </s:if>
										  </s:iterator>
										</td>
										<td>
											${clist.contractDepartment}
										</td>
										<td title="${clist.contractor}">
										    ${fn:substring(clist.contractor, 0, 7) }
										</td>
										<td>
										  ${clist.contractYear}
										</td>
										<td>
										<s:if test="#session.logUser.usercity == contractCity">
									    	<a href="#" title="编辑" onclick="javascript:contractMofify('${clist.contractID}');"> <img
													src="<%=request.getContextPath()%>/images/modify.gif" 
													alt="编辑" align="absmiddle" /> </a>
									    </s:if>
											<a href="#" title="详情" onclick="javascript:contractDetail('${clist.contractID}');"> <img
													src="<%=request.getContextPath()%>/images/detail.gif"
													alt="详情" align="absmiddle" /> </a>
										<s:if test="#session.logUser.usercity == contractCity">
									    	<a href="#" onclick="javascript:delContract('${contractID}');" title="删除"> <img
													src="<%=request.getContextPath()%>/images/delete.gif"
													alt="删除" align="absmiddle" /> </a>
									    </s:if>
										</td>
									</tr>
								</s:iterator>
							</table>
							<!-- 分页 -->
							<jsp:include page="/jsp/common/page.jsp"></jsp:include>
						</div>
					</form>
				</div>
			</div>
			</div>
		<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
		<div id="organizeContent" class="menuContent"
			style="display: none; position: absolute;">
			<ul id="organizesTree" class="ztree" style="margin-top: 0;"></ul>
		</div>
			<script type="text/javascript">
	
	//获取后台数据显示组织架构
	var organizes =${flag};
	
	//组织架构初始化
	var organizeSetting = {
		view : {
			dblClickExpand : false
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		callback : {
			beforeClick : beforeClick,
			onClick : organizeOnClick
		}
	};
		//页面加载
	$(function() {
		//设置组织架构弹出框
		$.fn.zTree.init($("#organizesTree"), organizeSetting, organizes);
		
		
	});

	//点击事件
	function beforeClick(treeId, treeNode) {
		var check = (treeNode && !treeNode.isParent);
		if (!check)
			alert("请选择下级节点！");
		return check;
	}

	//组织架构点击事件
	function organizeOnClick(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("organizesTree"), nodes = zTree.getSelectedNodes(), v = "";
		nodes.sort(function compare(a, b) {
			return a.id - b.id;
		});
		for ( var i = 0, l = nodes.length; i < l; i++) {
			v += nodes[i].name + ",";
		}
		if (v.length > 0)
			v = v.substring(0, v.length - 1);
		var orgNameObj = $("#showOrganize");
		orgNameObj.attr("value", v);
		//设置隐藏域中组织编号  
		$('#orgID').val(treeNode.id);
		hideMenu('organizeContent');
	}

	//隐藏组织架构
	function hideMenu(divId) {
		$("#" + divId).fadeOut("fast");
		$("body").unbind("mousedown", {
			tempDiv : divId
		}, onBodyDown);
	}

	//组织架构弹出窗
	function showMenu(objId, divId) {
		var cityObj = $("#" + objId);
		var cityOffset = $("#" + objId).position();
		$("#" + divId).css( {
			left : cityOffset.left + "px",
			top : cityOffset.top + cityObj.outerHeight() + "px"
		}).slideDown("fast");
		$("body").bind("mousedown", {
			tempDiv : divId
		}, onBodyDown);
	}
		//鼠标点击别的地方隐藏弹出属性菜单
	function onBodyDown(event) {
		var divId = event.data.tempDiv;
		if (!(event.target.id == "showOrganize" || $(event.target).parents(
				"#" + divId).length > 0)) {
			hideMenu(divId);
		}
	}
		//参数非空验证
	function paramIsNull(paramId){
		var temp = $('#'+paramId).val();
		if(null == temp || temp=='')
		{
			return false;
		}
		else{
			//文本框去左右空格重新赋值
			$('#'+paramId).val($.trim(temp));
			return true;
		}
	} 
	function getOrganization(cityContract)
	{
	   document.getElementById("orgID").value="--部门科室--";
	   document.getElementById("showOrganize").value="--部门科室--";
	   var value = cityContract;
	   if(value == null || value == '')
	   {
	      value = $("#cityContract").val();
	   }
	   if(null!=value&&value!='')
	   {
          var url = encodeURI(encodeURI('getOrganization.action?contractCitycode=' + value));
          $.ajax(
          {
        	url : url,
			type : "POST",
			dataType: "json",
			cache : false,
			success : function(message) {
			    var items = eval(message);
			    if(null != items){
			    	var orgFlag = items[0].flagstr;
			    	var treeObj = $.fn.zTree.getZTreeObj("organizesTree");
			    	var node_remove = treeObj.transformToArray(treeObj.getNodes());
			    	var tempNode= node_remove.length;
			    	for (var i=0; i< tempNode; i++) {
						treeObj.removeChildNodes(node_remove[i]);
					}
			    	var treeObj1 = $.fn.zTree.getZTreeObj("organizesTree");
			    	var node_remove1 = treeObj1.transformToArray(treeObj1.getNodes());
			    	var tempNodeo1 = node_remove1.length;
			    	for(var i=0; i< tempNodeo1; i++)
			        {
			    		treeObj1.removeNode(node_remove1[i]);
			    	}
			    	var treeObj = $.fn.zTree.getZTreeObj("organizesTree");
			    	var dataObj=eval("("+orgFlag+")");//转换为json对象 
			    	orgFlag = treeObj.addNodes(null, dataObj);
			    }
			}
          });
	   }
	
	}

	</script>
	</body>
</html>
